﻿using SqlSugar;
using SqlSugarEncapsulation.Common;
using System;
using System.Linq;
using System.Collections.Generic;


namespace SqlSugarEncapsulation.App
{
    class Program
    {
        static void Main(string[] args)
        {
            string guid = "bf1976d1-8ca9-4338-9f0b-6abd2fb80e6f";
            string guid02 = "bf1976d1-8ca9-4338-9f0b-6abd2fb80e60";
            string guid03 = "bf1976d1-8ca9-4338-9f0b-6abd2fb80e61";
            DateTime now = DateTime.Now;
            SqlSugarBase<Section> mysqlBusiness = new SqlSugarBase<Section>(DBEnum.MySqlADMP);
            SqlSugarBase<Section> sqlserverBusiness = new SqlSugarBase<Section>();

            #region 测试插入
            //Section section = new Section();
            //section.SID = new Guid(guid);
            //section.SName = "测试版块guid主键";
            //section.SCode = "901";
            //section.SectionStyle = null;
            //section.SectionCategory = 901;
            //section.IsEnable = 1;
            //section.UserID = new Guid("442f0e28-4d11-4e51-917d-cd93969e3405");
            //section.AppID = new Guid("ebe984af-9aee-4d5f-a8d9-8d2149d79128");
            //section.SubTime = now;
            //section.ModifiedOn = now;
            //section.HasGuan = "yes";
            //mysqlBusiness.Insert(section);
            //sqlserverBusiness.Insert(section);

            //List<Section> sectionList = new List<Section>();
            //Section section02 = new Section();
            //section02.SID = new Guid(guid02);
            //section02.SName = "测试版块02";
            //section02.SCode = "901";
            //section02.SectionStyle = null;
            //section02.SectionCategory = 901;
            //section02.IsEnable = 1;
            //section02.UserID = new Guid("442f0e28-4d11-4e51-917d-cd93969e3405");
            //section02.AppID = new Guid("ebe984af-9aee-4d5f-a8d9-8d2149d79128");
            //section02.SubTime = now;
            //section02.ModifiedOn = now;
            //section02.HasGuan = "yes";
            //Section section03 = new Section();
            //section03.SID = new Guid(guid03);
            //section03.SName = "测试版块03";
            //section03.SCode = "901";
            //section03.SectionStyle = null;
            //section03.SectionCategory = 901;
            //section03.IsEnable = 1;
            //section03.UserID = new Guid("442f0e28-4d11-4e51-917d-cd93969e3405");
            //section03.AppID = new Guid("ebe984af-9aee-4d5f-a8d9-8d2149d79128");
            //section03.SubTime = now;
            //section03.ModifiedOn = now;
            //section03.HasGuan = "yes";
            //sectionList.Add(section02);
            //sectionList.Add(section03);
            //mysqlBusiness.InsertRange(sectionList);
            //sqlserverBusiness.InsertRange(sectionList);
            #endregion

            #region 测试更新
            //Section section = new Section();
            //section.SID = Guid.NewGuid();
            //section.SName = "测试版块01new";
            //section.SCode = "901";
            //section.SectionStyle = null;
            //section.SectionCategory = 902;
            //section.IsEnable = 1;
            //section.UserID = new Guid("442f0e28-4d11-4e51-917d-cd93969e3405");
            //section.AppID = new Guid("ebe984af-9aee-4d5f-a8d9-8d2149d79128");
            //section.SubTime = now;
            //section.ModifiedOn = now;
            //section.HasGuan = "no";
            //section.SID = new Guid(guid);
            //mysqlBusiness.Update(section);
            //sqlserverBusiness.Update(section);

            //List<Section> sectionList = new List<Section>();
            //Section section02 = new Section();
            //section02.SID = new Guid(guid02);
            //section02.SName = "测试版块02new";
            //section02.SCode = "901";
            //section02.SectionStyle = null;
            //section02.SectionCategory = 901;
            //section02.IsEnable = 1;
            //section02.UserID = new Guid("442f0e28-4d11-4e51-917d-cd93969e3405");
            //section02.AppID = new Guid("ebe984af-9aee-4d5f-a8d9-8d2149d79128");
            //section02.SubTime = now;
            //section02.ModifiedOn = now;
            //section02.HasGuan = "yes";
            //Section section03 = new Section();
            //section03.SID = new Guid(guid03);
            //section03.SName = "测试版块03new";
            //section03.SCode = "901";
            //section03.SectionStyle = null;
            //section03.SectionCategory = 901;
            //section03.IsEnable = 1;
            //section03.UserID = new Guid("442f0e28-4d11-4e51-917d-cd93969e3405");
            //section03.AppID = new Guid("ebe984af-9aee-4d5f-a8d9-8d2149d79128");
            //section03.SubTime = now;
            //section03.ModifiedOn = now;
            //section03.HasGuan = "yes";
            //sectionList.Add(section02);
            //sectionList.Add(section03);
            //mysqlBusiness.UpdateRange(sectionList);
            //sqlserverBusiness.UpdateRange(sectionList);
            #endregion

            #region 测试查询
            //Section mysqlSection01 = mysqlBusiness.GetById(guid);
            //Section sqlserverSection01 = sqlserverBusiness.GetById(guid);
            //Section mysqlSection02 = mysqlBusiness.GetModel(item => item.SCode == "701" && item.IsEnable == 1);
            //Section sqlserverSection02 = sqlserverBusiness.GetModel(item => item.SCode == "701" && item.IsEnable == 1);
            //List<Section> mysqlSectionList01 = mysqlBusiness.GetList();
            //List<Section> sqlserverSectionList01 = sqlserverBusiness.GetList();
            List<string> ids = new List<string>() 
            { 
                "fb3e089f-c46c-4b03-8a15-0f8b087ee17d",
                "9b511138-6a64-4e06-a15b-13c69a04fb9e",
                "a2822cc9-77bb-45e4-ab9a-162616b99fbf"
            };
            List<Section> mysqlSectionList03 = mysqlBusiness.GetList(ids.ToArray());
            List<Section> sqlserverSectionList03 = sqlserverBusiness.GetList(ids.ToArray());
            //List<Section> mysqlSectionList02 = mysqlBusiness.GetList(item => item.SCode == "701" && item.IsEnable == 1);
            //List<Section> sqlserverSectionList02 = sqlserverBusiness.GetList(item => item.SCode == "701" && item.IsEnable == 1);
            //SqlSugar.PageModel pageModel = new SqlSugar.PageModel();
            //pageModel.PageIndex = 0;
            //pageModel.PageSize = 5;
            //List<Section> mysqlSectionList03 = mysqlBusiness.GetPageList(item => item.IsEnable == 1, pageModel, item => item.SCode);
            //List<Section> sqlserverSectionList03 = sqlserverBusiness.GetPageList(item => item.IsEnable == 1, pageModel, item => item.SCode);
            #endregion

            #region 测试删除
            //mysqlBusiness.DeleteById(guid);
            //sqlserverBusiness.DeleteById(guid);
            //mysqlBusiness.DeleteByIds(new string[] { guid02, guid03 });
            //sqlserverBusiness.DeleteByIds(new string[] { guid02, guid03 });
            //mysqlBusiness.Delete(item => item.SCode == "901" && item.IsEnable == 1 && string.Equals(item.HasGuan, "yes", StringComparison.OrdinalIgnoreCase));
            //sqlserverBusiness.Delete(item => item.SCode == "901" && item.IsEnable == 1 && string.Equals(item.HasGuan, "yes", StringComparison.OrdinalIgnoreCase));
            #endregion

            #region 测试ext
            string sql01 = @"select t1.*,t2.RoleName from Section t1
                             inner join RoleSection t2 on t1.SID = t2.SID
                             where SCode in(701, 702, 703, 704); ";
            string sql02 = @"select t1.*,t2.RoleName from Section t1
                             inner join RoleSection t2 on t1.SID = t2.SID
                             where SCode=@SCode; ";
            SectionExt mysqlSectionExt = mysqlBusiness.GetModel<Section, SectionExt>(sql01, null);
            SectionExt sqlserverSectionExt = sqlserverBusiness.GetModel<Section, SectionExt>(sql01, null);
            List<SectionExt> mysqlSectionExtList = mysqlBusiness.GetList<Section, SectionExt>(sql01, null).ToList();
            List<SectionExt> sqlserverSectionExtList = sqlserverBusiness.GetList<Section, SectionExt>(sql01, null).ToList();
            List<SugarParameter> parameters = new List<SugarParameter>();
            parameters.Add(new SugarParameter("@SCode", "701"));
            SectionExt mysqlSectionExt02 = mysqlBusiness.GetModel<Section, SectionExt>(sql02, parameters);
            SectionExt sqlserverSectionExt02 = sqlserverBusiness.GetModel<Section, SectionExt>(sql02, parameters);
            List<SectionExt> mysqlSectionExtList02 = mysqlBusiness.GetList<Section, SectionExt>(sql02, parameters).ToList();
            List<SectionExt> sqlserverSectionExtList02 = sqlserverBusiness.GetList<Section, SectionExt>(sql02, parameters).ToList();
            #endregion

            Console.WriteLine("Hello World!");
        }
    }
}
